﻿using MCPlatform.MotionLib.Base;
using MCPlatform.MotionLib.Base.Models;
using MCPlatform.UI.Controls.AssistantMethods.StaticMethods;
using MCPlatform.UI.Controls.Converts;
using MCPlatform.UI.Controls.Models;
using Panuon.WPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Input;

namespace MCPlatform.Models
{
    public class AxisModel : NotifyPropertyChangedBase
    {
        #region Properties
        public IMotion? MotionEntity 
        { 
            get => _MotionEntity;
            set { Set(ref _MotionEntity, value); Initial(); }
        }
        private IMotion? _MotionEntity  ;
        public MotionModel MotionModel { get => _MotionModel; set => Set(ref _MotionModel, value); }
        private MotionModel _MotionModel = new MotionModel();

        public MotionParaModel MotionParaModel { get => _MotionParaModel; set => Set(ref _MotionParaModel, value); }
        private MotionParaModel _MotionParaModel = new MotionParaModel();

        #endregion

        #region Methods

        Timer timer;
        public void StartMappingEntityToModel()
        {
            if (MotionEntity is null)
            {
                return;
            }

            timer.Start();


        }


        public void StopMappingEntityToModel()
        {
            
            timer.Stop();


        }

        #endregion

        #region CTOR

        public AxisModel()
        {
            timer = new Timer(200);
            timer.Elapsed += Timer_Elapsed;

          
        }

      
        private void Timer_Elapsed(object? sender, ElapsedEventArgs e)
        {
           
            MotionParaModel.MotionEntity = MotionEntity;
            MotionModel.MotionEntity = MotionEntity;

            MotionModel.Mapping();

            
        }

        public void Initial()
        {
            MotionParaModel.MotionEntity = MotionEntity;
            MotionModel.MotionEntity = MotionEntity;
        }
        #endregion
    }
}
